if (OBJECT_ID('sp_getFriends') is not null)
	drop procedure sp_getFriends;
go

create procedure [dbo].[sp_getFriends]
@userID varchar(100)
as
select RequestToID as UserID, UserName, FriendCategory,CategoryName,
IsApproved,IsSeen from Friend
join aspnet_Users on RequestToID = aspnet_Users.UserId
join FriendCategory on friend.FriendCategory = FriendCategory.CategoryID
where RequestFromID = @userID and IsApproved = 1
and RequestFromID not in
(select RequestToID from Friend where RequestToID <> @userID)

union

select RequestFromID as UserID, UserName, FriendCategory,CategoryName,
IsApproved,IsSeen from Friend
join aspnet_Users on RequestFromID = aspnet_users.userid
join FriendCategory on friend.FriendCategory = FriendCategory.CategoryID
where RequestToID = @userID and IsApproved = 1
and RequestToID not in
(select RequestFromID from Friend where RequestFromID <> @userID)